package kr.co.doriclassic.lab21;

import java.util.Scanner;

public class ExceptionTest {
	public static void main(String[] args) {
		int[] list;
		int sum=0;
		int count;
		
		try {
			Scanner sc = new Scanner(System.in);
			//Scanner sc = null;//NullPointException
			System.out.print("정수의 개수:");
			count = sc.nextInt();
			//count = 0;//ArithmeticException
			list = new int[count];
			//list = new int[-1];//NegativeArraySizeException
			
			for (int i = 0; i < count; i++) {
				System.out.print("정수를 입력하시오:");
				list[i]=sc.nextInt();
			}
			/*for (int i = 0; i <= count; i++) {//ArrayIndexOutOfBoundsException
				System.out.print("정수를 입력하시오:");
				list[i]=sc.nextInt();
			}*/
			
			for (int i = 0; i < count; i++) {
				sum+=list[i];
			}
			
			System.out.println("평균은 "+sum/count);
		} catch (ArithmeticException e) {
			System.out.println("0으로 나눌 수 없음");
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("범위가 초과되었습니다.");
		} catch (NegativeArraySizeException e) {
			System.out.println("배열의 인자는 음수가 나올 수 없습니다.");
		} catch (NullPointerException e) {
			System.out.println("객체가 생성되지 않았습니다.");
		}
	}
}
